package cemp.controller;


import cemp.common.api.reponse.RestCommonResponse;
import cemp.common.api.reponse.RestStockAllResponse;
import cemp.common.api.reponse.RestStockPlates;
import cemp.service.StockCoreService;
import com.fetchdata.api.FetchDataApi;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@AllArgsConstructor
@RequestMapping("/fetch")
public class FetchDataController {

    private final StockCoreService stockCoreService;
    private final FetchDataApi fetchDataApi;

    @GetMapping("/stocks")
    public List<RestStockAllResponse> list() {
        return fetchDataApi.getAllStocks();
    }

    @GetMapping("/plates")
    public RestCommonResponse list(@RequestParam(value = "pageNum",required = false) Integer pageNum,
                                   @RequestParam(value = "pageSize",required = false) Integer pageSize) {
        return fetchDataApi.getPlates(pageNum,pageSize);
    }

    @GetMapping("/plate/stocks")
    public RestCommonResponse getPlateStocks(@RequestParam(value = "pageNum",required = false) Integer pageNum,
                                             @RequestParam(value = "pageSize",required = false) Integer pageSize,
                                             @RequestParam(value = "platecode",required = false) String platecode) {
        return fetchDataApi.getPlateStocks(pageNum,pageSize,platecode);
    }

    @GetMapping("/getStockInfo")
    public RestCommonResponse getStockInfo(@RequestParam(value = "stockCode",required = false) String stockCode) {
        return fetchDataApi.getStockInfo(stockCode);
    }

    @GetMapping("/getStockDetail")
    public RestCommonResponse getStockDetail(@RequestParam(value = "stockCode",required = false) String stockCode) {
        return stockCoreService.getStockDetail(stockCode);
    }

    @GetMapping("/plate/options")
    public RestCommonResponse getPlateOptions() {
        return stockCoreService.getPlateOptions();
    }

    @GetMapping("/stock/info/today")
    public RestCommonResponse getInfoToday(@RequestParam(value = "stockCode",required = true) String stockCode) {
        return stockCoreService.getInfoToday(stockCode);
    }



}
